package com.wk.unreal.dingroomserver.util;

public class ThreadLocalUtil {

    // 提供 ThreadLocal 对象
    private static final ThreadLocal THREAD_LOCAL = new ThreadLocal();

    // 根据 key 获取值
    public static <T> T get () {
        return (T) THREAD_LOCAL.get();
    }

    // 存储键值对
    public static void set (Object value) {
        THREAD_LOCAL.set(value);
    }

    // 清除 ThreadLocal 防止内存泄露
    public static void remove () {
        THREAD_LOCAL.remove();
    }

    public static void main(String[] args) {

        ThreadLocalUtil.set("unreal");

        Object o = ThreadLocalUtil.get();

        System.out.println(o);

        ThreadLocalUtil.remove();

        Object o1 = ThreadLocalUtil.get();
        System.out.println(o1);


    }

}
